package com.example.neusoftfood_c213_zhong.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.neusoftfood_c213_zhong.R;
import com.example.neusoftfood_c213_zhong.adapter.ShopAdapter;
import com.example.neusoftfood_c213_zhong.beans.Shop;
import com.example.neusoftfood_c213_zhong.listener.RetrofitListener;
import com.example.neusoftfood_c213_zhong.model.ShopModel;

import java.util.List;

public class HomeFragment extends BaseFragment implements RetrofitListener<List<Shop>> {

    private RecyclerView recyclerView;
    private ShopAdapter adapter;



    private View view = null;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_fragment1, container, false);
        initViews();
        initData();

        return view;
    }

    void initViews() {
        recyclerView = (RecyclerView) view.findViewById(R.id.recycleview);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));


    }

    @Override
    void initEvents() {

    }

    void initData() {
        ShopModel shopModel = new ShopModel();
        shopModel.getAllShops(this);

    }

    @Override
    public void onSuccess(List<Shop> shops, int flag) {
        adapter =  new ShopAdapter(getActivity(), shops, R.layout.item);
        recyclerView.setAdapter(adapter);

    }

    @Override
    public void onFail() {


    }
}
